package com.unsafe;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 解决map不安全的问题
 */
public class MapTest {

    public static void main(String[] args) {
        Map<Integer, String> map = new ConcurrentHashMap<>();

        for (int i = 0; i < 30; i++) {
            int finalI = i;
            new Thread(() -> {
                map.put(finalI, Thread.currentThread().getName());
            }, String.valueOf(i)).start();
            System.out.println(map);
        }


    }
}
